package com.zhengsr.colorselector;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ImageView;
import android.widget.SeekBar;
import android.widget.Toast;

import com.mstar.android.tv.iapi.IstEventManager;
import com.mstar.android.tv.iapi.IstRecentBean;

import java.util.List;

public class MainActivity extends AppCompatActivity {
    private static final String TAG = "MainActivity";
    private int red,green,blue;
    private int alpha = 255;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ColorView colorView = (ColorView) findViewById(R.id.colorview);
        final View testview = findViewById(R.id.testview);
        colorView.setColorListener(new ColorView.ColorListener() {
            @Override
            public void getColor(int color) {
                red =  color >> 16 & 0XFF;
                green = color >> 8 & 0XFF;
                blue = color  & 0XFF;
                testview.setBackgroundColor(Color.argb(255,red,green,blue));
            }
        });

        SeekBar seekbar = (SeekBar) findViewById(R.id.alpha_seekbar);
        seekbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            @Override
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                alpha = progress;
                testview.setBackgroundColor(Color.argb(alpha,red,green,blue));
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {

            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {

            }
        });

        SeekBar lightbar = (SeekBar) findViewById(R.id.light_seekbar);
        lightbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            @Override
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                float d = progress / 255.0f;

                testview.setBackgroundColor(Color.argb(alpha,
                        (int) (red * d),
                        (int) (green * d),
                        (int) (blue * d)));
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {

            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {

            }
        });


    }
}
